<?php
namespace App\Repositories\Backend;

use App\Models\Combo;
use Illuminate\Support\Facades\Auth;

class ComboRepository extends CommonRepository
{

    public function __construct(Combo $combo)
    {
        parent::__construct($combo);
    }

    /**
     * 列表
     * @param  array $input 查询条件
     * @return object
     */
    public function getLists($input)
    {
        $default_search = [
            'filter' => ['id', 'combos_name', 'combos_now_price', 'combos_ago_price','combos_images1', 'combos_images2', 'order', 'created_at'],
            'sort'   => [
                'order' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->parseWheres($search)->with('branch', 'parameter')->paginate();
    }


    /**
     * 新增
     * @param  float  $combos_ago_price    老价格
     * @param  string $combos_name         标题
     * @param  float  $combos_now_price    新价格
     * @param  int    $order               排序
     * @param  string $combos_images1      图片路径
     * @return object
     */
    public function create($combos_ago_price, $combos_name, $combos_now_price, $order, $combos_images1, $combos_images2)
    {
        $result = $this->model->create([
            'combos_ago_price' => $combos_ago_price,
            'combos_name'      => $combos_name,
            'combos_now_price' => $combos_now_price,
            'order'            => $order,
            'combos_images1'   => $combos_images1,
            'combos_images2'   => $combos_images2,
        ]);

        return $result;
    }

    public function destroy($id)
    {

        return $this->deleteById($id);;
    }

    public function getoneDatas($input)
    {
        $default_search = [
            'filter' => ['id', 'combos_name', 'combos_now_price', 'combos_ago_price','combos_images1', 'combos_images2', 'order', 'created_at'],
            'sort'   => [
                'order' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->where($input)->with('branch', 'parameter')->paginate();
    }


}